package main

import (
	"errors"
	"fmt"
)

type myError struct{
	arg int
	errMsg string
}

func (e *myError) Error() string{
	return fmt.Sprintf("%d - %s",e.arg,e.errMsg)
}

func error_test(code int)(int,error){
	if code < 0{
		return -1,errors.New("Bad Arguments - negative!")
	}else if code > 256{
		return -1,&myError{code,"Bad Arguments - too large!"}
	}
	return code*code,nil
}

func main(){
	for _,i:=range []int{-1,4,1000}{
		if r,e:=error_test(i);e!=nil{
			fmt.Println("failed: ",e)
		}else{
			fmt.Println("success: ",r)
		}
	}
}